package applicationAlibi;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;

import tables.JdbcAlibi;

public class Test_BDD {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws SQLException,
			ClassNotFoundException, IOException {

		File f = new File("/home/auberi/Bureau/rapport_test_bdd.txt");
		FileWriter fw = new FileWriter(f);
		fw.write("test\n");

		ArrayList<String> champs = new ArrayList<String>();
		ArrayList<String> tables = new ArrayList<String>();
		ArrayList<Object> s1 = new ArrayList<Object>();
		ArrayList<Object> s2 = new ArrayList<Object>();

		tables.add("alibi");
		s1.add("pseudo");
		s2.add("pseudoo");
		
		fw.write("On recherche :\n" +
				"SELECT * FROM alibi\n" +
				"WHERE pseudo = 'pseudoo'\n");

//		GregorianCalendar c = new GregorianCalendar();
//		Date d = c.getTime();
//
//		Object[] s = new Object[] { 1, "pseudoo", d, "email", "lille",
//				"conjoint" };
//		JdbcAlibi.insere(s);

		try {
			Object[] r = JdbcAlibi.recherche(champs, tables, s1, s2);
			fw.write("\n" + "**********************************"
					+ "**********************************"
					+ "**********************************"
					+ "************" + "\n");

			// On affiche le nom des colonnes
			fw.write("*");
			for (int i = 0; i < r.length; i++) {
				fw.write("   " + ((ArrayList<Object>) r[i]).get(0) + "\t *");
			}			
			
			fw.write("\n" + "**********************************"
					+ "**********************************"
					+ "**********************************"
					+ "************" + "\n");

			int longueur = ((ArrayList<Object>) r[0]).size();
			int j = 1;
			while (j < longueur) {
				for (int i = 0; i < r.length; i++) {
					fw.write("\t"
							+ ((ArrayList<Object>) r[i]).get(j).toString()
							+ "\t |");
				}
				fw.write("\n" + "---------------------------------"
						+ "---------------------------------"
						+ "---------------------------------"
						+ "---------------" + "\n");
				fw.close();

			}
		} catch (Exception e) {
			fw.write(e + "\n");
			fw.close();
		}
	}
}
